﻿from django.db import transaction
from django.shortcuts import render_to_response
from onecall.main.models import Service
from django.contrib.admin.views.decorators import staff_member_required
from django.template import RequestContext
from django.http import HttpResponseRedirect

from onecall.main.forms import *

def base(request):
    return render_to_response(
        "base.html",{},
        RequestContext(request, {}),
    )


def import_main(request):

    from onecall.main.import_files import handle_uploaded_file,main_import_types
    if request.method == 'POST':
        form = MainImportForm(request.POST,request.FILES)
        if form.is_valid():
            report = handle_uploaded_file(request.FILES['file'],request.POST['choises'])
            return render_to_response('import_report.html',locals(),RequestContext(request, {}),)
    else:
        form = MainImportForm()
    return render_to_response('import_main.html', locals(), RequestContext(request, {}),)
    
def import_kladr(request):

    from onecall.main.import_files import handle_uploaded_file,kladr_import_types
    if request.method == 'POST':
        form = KladrImportForm(request.POST,request.FILES)
        if form.is_valid():
            report = handle_uploaded_file(request.FILES['file'],request.POST['choises'])
            return render_to_response('import_report.html',locals(),RequestContext(request, {}),)
    else:
        form = KladrImportForm()
    return render_to_response('import_kladr.html', locals(), RequestContext(request, {}),)    
    
def import_result(request):
    pass
    

def search_clinic(request):
    return render_to_response(
        "search_clinic.html",
        {'service_list' : Service.objects.all()},
        RequestContext(request, {}),
    )
        
search_clinic = staff_member_required(search_clinic)
base = staff_member_required(base)
import_main = staff_member_required(import_main)
import_kladr = staff_member_required(import_kladr)
